//
// Created by jyh on 2021/8/5.
//

#include "Rnxeph.h"
#include "Com.h"

struct Rnxeph BRDEPH;
int map_gpseph_find(struct GPSEPH *gnsseph, char keyprn[LEN_PRN]){
    int i;
    for(i=0;i<BRDEPH.size_gnssEph;i++){
        if(strstr(gnsseph[i].cprn, keyprn))
            return i;
    }
    return -1;
}
int map_glseph_find(struct GLSEPH *glseph, char keyprn[LEN_PRN]){
    int i;
    for(i=0;i<BRDEPH.size_glsEph;i++){
        if(strstr(glseph[i].cprn, keyprn))
            return i;
    }
    return -1;
}

void Rnxeph_GPSEPH_initial(struct GPSEPH *eph){
    memset(eph->cprn,0,sizeof(eph->cprn));
    eph->dt=1e6;
    eph->mjd=0;
    eph->sod=0;
    eph->a0=eph->a1=eph->a2=0;
    eph->aode=(unsigned int)0;
    eph->crs=eph->dn=0;
    eph->m0=eph->cuc=eph->e=0;
    eph->cus=eph->roota=0;
    eph->toe=eph->cic=eph->omega0=0;
    eph->cis=eph->i0=eph->crc=0;
    eph->omega=eph->omegadot=0;
    eph->idot=eph->resvd0=eph->week=eph->resvd1=0;
    eph->accu=eph->hlth=eph->tgd=eph->tgd1=eph->aodc=0;
    eph->iodc=eph->signal_idx=eph->delta_A=eph->A_DOT=eph->delta_n_dot=0;
}
void Rnxeph_GLSEPH_initial(struct GLSEPH *ephr){
    memset(ephr->cprn,0,sizeof(ephr->cprn));
    ephr->dt=1e6;
    ephr->mjd=0; ephr->aode=0;
    ephr->sod=0;
    ephr->tau=0;
    ephr->gamma=0;
    ephr->tk=0;
    ephr->pos[3]=0;
    ephr->vel[3]=0;
    ephr->acc[3]=0;
    ephr->health=0;
    ephr->frenum=0;
    ephr->age=0;
}
void Rnxeph_initial(){
    memset(&BRDEPH,0,sizeof(struct Rnxeph));
    for(int i=0; i<MAXSAT; i++){
        if(index_string(SYS,DLY.SAT[i].cprn[0])!=-1){
            if(DLY.SAT[i].cprn[0]!='R'){
                strcpy(BRDEPH.gnsseph[BRDEPH.size_gnssEph].cprn, DLY.SAT[i].cprn);
                BRDEPH.size_gnssEph++;
            }else {
                strcpy(BRDEPH.glseph[BRDEPH.size_glsEph].cprn, DLY.SAT[i].cprn);
                BRDEPH.size_glsEph++;
            }
        }
    }
}
